import { usePageRequest, useRequest } from "../../../utils/request";

Component({
    properties: {},
    data: {
        showInfoStatus: false
    },
    methods: {
        onLoad(options) {
            this.setData({
                ...options
            })
            this.baseRequest = new useRequest('api/houseownerinfo', {
                params: { house_user_id: options.id, },
                data: 'base'
            }, this)

            this.listRequest = new usePageRequest('api/userhouselist', {
                params: { house_user_id: options.id, },
                data: 'list',
                loading: 'listLoading'
            }, this)

            this.favoriteRequest = new useRequest('api/collectall', {
                params: { type: 2, own_user_id: options.id },
                loading: false,
                hold: true
            }, this)

            this.unFavoriteRequest = new useRequest('api/cancercollectdata', {
                params: { type: 2, own_user_id: options.id },
                loading: false,
                hold: true
            }, this)
        },
        onShareAppMessage() {
            return {
                title: '拥有一房，换游天下',
                path: '/pages/landlord/detail/detail?id=' + this.data.id
            }
        },
        favorite() {
            if (this.data.base.is_collect) {
                this.unFavoriteRequest.run().then(() => {
                    this.setData({
                        ['base.is_collect']: false
                    })
                })
            } else {
                this.favoriteRequest.run().then(() => {
                    this.setData({
                        ['base.is_collect']: true
                    })
                })
            }
        },
        showInfo() {
            this.setData({
                showInfoStatus: true
            })
        },
        hideInfo() {
            this.setData({
                showInfoStatus: false
            })
        }
    }
});
